var core = require('core');
var wechat = core.wechat;

var route = function(){
    this.use('/', route.wechat);
    this.use('/getList', route.getList);
    this.use('/tags', route.tags);
    this.use('/qrcode', route.qrcode);
    this.use('/admin', route.admin);
    this.use('/open', route.open);

    // catch 404 and forward to error handler
    this.use(function(req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
    });

    // error handler
    this.use(function(err, req, res, next) {
      if(req.error){
          var err = req.error;
          err.docs.jssdk = wechat.getJSSDK(req.originalUrl);
          return res.render('admin/error', err);
      }
      // set locals, only providing error in development
      res.locals.message = err.message;
      res.locals.error = req.app.get('env') === 'development' ? err : {};

      // render the error page
      res.status(err.status || 500);
      res.render('error');
    });

};

route.wechat = require('./routes/index');
route.getList = require('./routes/getList');
route.tags = require('./routes/tags');
route.admin = require('./routes/admin');
route.open = require('./routes/open');
route.qrcode = require('./routes/qrcode');

module.exports = route;
